//Page Object
const url = require('../../config/config.js')
Page({
    data: {
        id: 0,
        goodsInfo: [],
        tabIndex: 4 + '',
        // state状态
        state: 4

    },
    onShow() {
        // 读取token，如果token不存在,直接不给予返回
        const token = wx.getStorageSync("token");
        console.log(token)
        if (!token) {
            wx.navigateTo({
                url: '/pages/login/index'
            });
        }
    },

    //options(Object)
    onLoad: function(options) {
        this.setData({
            id: options.id
        })
        this.getGoodsInfo()
    },
    getGoodsInfo() {
        //从AppData中结构赋值
        const { id } = this.data
        const header = {
            'content-type': 'application/json',
            'Cookie': "JSESSIONID=" + wx.getStorageSync("token") //读取cookie
        }
        wx.request({
            url: url.b.getOrder,
            data: { id: id },
            header: header,
            method: 'GET',
            dataType: 'json',
            responseType: 'text',
            success: (result) => {
                try {
                    console.log(result)
                    const { fabricList } = result.data.data.orderData
                    console.log(fabricList)
                    wx.showLoading({
                        title: "加载中",
                        mask: true,

                    });
                    this.setData({
                        goodsInfo: fabricList
                    })
                    wx.hideLoading();
                } catch (error) {
                    wx.showToast({
                        title: '登陆过期',
                        icon: 'none',
                    });
                    wx.removeStorageSync({ token: "token" });
                    wx.navigateTo({
                        url: '/pages/login/index',

                    });

                }
            }
        });
    },

    // 点击修改样式
    handleTap(e) {
        const { state } = e.currentTarget.dataset;
        console.log(state)
            // 修改tabIndex的状态
        this.setData({
            tabIndex: state,
            state
        })
        console.log(state);

    },

});